part of 'component.dart';

class BottomBar extends StatelessWidget {
  const BottomBar({
    Key? key,
    required this.children,
    this.hasTopLine = true,
    this.mainAxisAlignment = MainAxisAlignment.spaceEvenly,
  }) : super(key: key);
  final List<Widget> children;
  final bool hasTopLine;
  final MainAxisAlignment mainAxisAlignment;
  @override
  Widget build(BuildContext context) {
    return children.isEmpty
        ? const SizedBox()
        : Container(
            padding: EdgeInsets.only(
              top: 10.r,
              bottom: Get.mediaQuery.viewPadding.bottom > 0 ? 0 : 10.r,
            ),
            decoration: BoxDecoration(
              color: Colors.white,
              border: hasTopLine ? Border(top: ITheme.borderSide) : null,
            ),
            child: SafeArea(
              child: Row(
                mainAxisAlignment: mainAxisAlignment,
                children: children,
              ),
            ),
          );
  }
}

class BtnBar extends StatelessWidget {
  const BtnBar({
    Key? key,
    this.left = '取消',
    this.right = '确认',
    this.hasTopLine = true,
    required this.onTap,
  }) : super(key: key);
  final String? left;
  final String? right;
  final bool hasTopLine;
  final ValueChanged<int> onTap;
  @override
  Widget build(BuildContext context) {
    var titles = [
      if (!isNilStr(left)) left!,
      if (!isNilStr(right)) right!,
    ];
    return titles.isEmpty
        ? const SizedBox()
        : Container(
            decoration: BoxDecoration(
              color: Colors.white,
              border: hasTopLine ? Border(top: ITheme.borderSide) : null,
            ),
            child: SeparatorRow(
              // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: titles
                  .asMap()
                  .map((i, v) {
                    Color color = ITheme.contentColor;
                    if (i == titles.length - 1) {
                      color = ITheme.selectedColor;
                    }
                    return MapEntry(
                        i,
                        Expanded(
                            child: MaterialButton(
                          onPressed: () {
                            if (titles[i] == left) {
                              onTap(0);
                            } else {
                              onTap(1);
                            }
                          },
                          height: 50.r,
                          textColor: color,
                          child: Text(
                            titles[i],
                            style: TextStyle(fontSize: 16.sp),
                          ),
                        )));
                  })
                  .values
                  .toList(),
              separatorBuilder: (index) => Container(
                color: ITheme.borderColor,
                width: 0.5,
                height: 50.r,
              ),
            ),
          );
  }
}
